<?php

namespace app\admin\controller;

use app\admin\service\EarlyWarningService;
use think\Request;

class EarlyWarning extends Backend
{
    /**
     * @var EarlyWarningService
     */
    protected $service;

    protected function initialize()
    {
        parent::initialize();
        $this->service = new EarlyWarningService();
    }

    /**
     * @throws \Exception
     */
    public function task() {
        $this->service->task();
    }

    public function list()
    {
        $data = $this->service->list();
        $this->jsonReturn($data);
    }

    public function rule(Request $request)
    {
        $id   = $request->param('id');
        $data = $this->service->rule($id);
        $this->jsonReturn($data);
    }

    public function ruleSave(Request $request)
    {
        $param = $request->except(['create_user', 'create_time', 'update_user', 'update_time', 'mark']);
        $this->service->ruleSave($param, $this->userId);
        $this->jsonReturn(['code' => 0, 'msg' => 'success', 'data' => '']);
    }

    public function ruleDelete()
    {
        $id = $this->request->param('id');
        $this->service->ruleDelete($id);
        $this->jsonReturn(message());
    }

}
